<?php

define ('NUMBER', 1);
define ('STRING', 2);
define ('BOOLEAN', 3);


class parametro extends ActiveRecord {
	public $id_servicio;
	public $id_parametro;
	public $in_out;
	public $nombre;
	public $tipo;
	
	public function __construct ($datos = null) {
        parent::__construct ($datos);
	}

    public function insert() {
        $sql = "INSERT INTO parametros 
                (id_servicio, id_parametro, nombre, tipo, in_out)
                VALUES
                ($this->id_servicio, $this->id_parametro, '$this->nombre', $this->tipo, $this->in_out)";
        return $this->id = executeId($sql);
    }

    public function update($datos = null) {
        $this->__cargarParametros($datos);
        $sql = "UPDATE parametros
                SET id_servicio = $this->id_servicio,
					id_parametro = $this->id_parametro,
					in_out = $this->in_out,
					nombre = '$this->nombre',
					tipo = $this->tipo
                WHERE id = $this->id";
        return execute($sql);
    }

	public function delete() {
		$parametros = $this->parametros();
		foreach ($parametros as $parametro) {
			$parametro->delete();
		}
		return parent::delete();
	}

	public function save($in_out, $servicio) {
		$this->in_out = $in_out;
		$this->id_servicio = $servicio->id;		
		parent::save();
	}

	public function find($id_servicio, $id_parametro, $in_out) {
		foreach ($parametros as $parametro) {
			$parametro->delete();
		}
		return parent::delete();
	}
	
	public function find_by_servicio($servicio) {
		$sql = "SELECT * FROM parametros
				WHERE id_servicio = '$servicio' AND in_out = '1'";
		return queryObjectList($sql, $this->getClass());
	} 
	
	public function find_returns_by_servicio($servicio) {
		$sql = "SELECT * FROM parametros
				WHERE id_servicio = '$servicio' AND in_out = '2'";
		return queryObjectList($sql, $this->getClass());
	} 

}

?>